import request from '/utils/http.js';
import requestHandler from '@/utils/requestHandler';

export async function getUsers() {
	return requestHandler('/api/user/getAllUser', 'GET');
}

export async function getUserByAccount(account) {
	const result = await getUsers();
	let data = null;
	result.data.forEach(d => {
		if (d.account === account) {
			data = d;
		}
	});
	return data;
}

export async function getManagersByAreaId(areaId) {
	return await requestHandler('/api/area/getUsersByAreaId', 'POST', {}, {
		areaId
	});
}

export async function updateUser(data = {}) {
	const body = {};
	for (let key in data) {
		body[key] = data[key];
	}
	console.log(body);
	return await requestHandler('/api/user/update', 'POST', {}, body);
}

export async function getOperationLog(data = {}) {
	return await requestHandler('/api/user/getOperationLog', 'POST', {}, {
		...data
	});
}